// run: $exec < bfdiff.in
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;

#define PB push_back
#define LL long long

const int N = 1e5 + 5;

struct E {
	int v, next;
} p[2 * N];

int head[N], tot;

void addEdge(int u, int v) {
	p[tot].v = v;
	p[tot].next = head[u];
	head[u] = tot ++;
}

vector<int> fac[N];
int a[N];
LL ans[N];
LL cnt[N];

int mu[N];
//O(nlog(n))
void getMu() {
	for (int i = 1; i < N; ++i) {
		int target = i == 1 ? 1 : 0;
		int delta = target - mu[i];
		mu[i] = delta;
		for (int j = 2 * i; j < N; j += i)
			mu[j] += delta;
	}
}


LL cal(int x) {
	LL ret = 0;
	//
	for(int i = 0; i < fac[x].size(); ++i) {
		int val = fac[x][i];
		ret += mu[val] * cnt[val];
	}
	return ret;
}

void dfs(int u, int fa) {
	int val;
	for(int i = head[u]; i != -1; i = p[i].next) {
		int v = p[i].v;
		if(v == fa) continue;

		val = a[v];
		LL pre = cal(val);
		dfs(v, u);
		LL now = cal(val);
		ans[v] = now - pre;
		if(val == 1) --ans[v];
	}
	val = a[u];
	for(int i = 0; i < fac[val].size(); ++i) {
		++cnt[fac[val][i]];
	}
}

void In(int &x) {
	char c; x = 0; c = getchar();
	int sign = 1;
	while (!((c >= '0' && c <= '9') || c == '-')) c = getchar();
	if (c == '-') sign = -1, c = getchar();
	while (c >= '0' && c <= '9') {
		x = (x << 3) + (x << 1) + c - '0';
		c = getchar();
	}
	x *= sign;
}

void In(LL &x) {
	char c; x = 0; c = getchar();
	int sign = 1;
	while (!((c >= '0' && c <= '9') || c == '-')) c = getchar();
	if (c == '-') sign = -1, c = getchar();
	while (c >= '0' && c <= '9') {
		x = (x << 3) + (x << 1) + c - '0';
		c = getchar();
	}
	x *= sign;
}

void Out(int x) {
	if (x < 0) { x = -x; putchar('-');}
	if (x > 9)
		Out(x / 10);
	putchar(x % 10 + '0');
}

void Out(LL x) {
	if (x < 0) { x = -x; putchar('-');}
	if (x > 9)
		Out(x / 10);
	putchar(x % 10 + '0');
}


void gao(int n) {
	dfs(1, -1);
	ans[1] = cal(a[1]);
	if(a[1] == 1) --ans[1];
	printf("%lld", ans[1]);
	for(int i = 2; i <= n; ++i) {
		printf(" %lld", ans[i]);
	}
	puts("");
}

void init(int n) {
	memset(cnt, 0, sizeof(cnt));
	memset(head, -1, sizeof(head));
	tot = 0;
}

void deal(int x) {
	for(int i = 1; i * i <= x; ++i) {
		if(x % i == 0) {
			fac[x].PB(i);
			int tmp = x / i;
			if(tmp != i) fac[x].PB(tmp);
		}
	}
}

void getFac() {
	for(int i = 1; i < N; ++i) {
		deal(i);
	}
}

int main() {
	getMu();
	getFac();
	int n;
	int cas = 0;
	while(scanf("%d", &n) != EOF) {
		init(n);
		for(int i = 0; i < n - 1; ++i) {
			int u, v;
			//In(u); In(v);
			scanf("%d%d", &u, &v);
			addEdge(u, v);
			addEdge(v, u);
		}

		for(int i = 1; i <= n; ++i) {
			//In(a[i]);
			scanf("%d", &a[i]);
		}

		printf("Case #%d: ", ++cas);
		gao(n);
	}
	return 0;
}
